from sqlalchemy import Column, Integer, String,DateTime
from sqlalchemy.orm import relationship
from core.base.orm_model import Base, TimestampMixin
from datetime import datetime


class DictType(Base, TimestampMixin):
    __tablename__ = "dict_type"

    id = Column(Integer, primary_key=True, index=True)
    type_code = Column(String(50), unique=True, nullable=False)
    type_name = Column(String(100), nullable=False)
    type_desc = Column(String(200))
    create_time = Column(DateTime, default=datetime.now, comment="创建时间")
    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment="更新时间")

    items = relationship("Dictionary", back_populates="dict_type_rel", cascade="all, delete-orphan")

    def __repr__(self):
        return f"<DictType {self.type_name}>"